<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class AddreController extends Controller
{
    public function index()
    {
    	$userid = session('homeuser')->userid;
    	$list = DB::table('cloud')->whereNotNull('username')->where('userid',$userid)->get();
    	return view('home.cloud.addre',['list'=>$list]);
    }
    public function destroy($id)
    {
    	DB::table('cloud')->where('cloudid',$id)->delete();
    	return redirect('home/addre');
    }
    public function create()
    {
    	$userid = session('homeuser')->userid;
    	return view('home.cloud.add',['userid'=>$userid]);
    }
    public function store(Request $request)
    {
    	if ($request->has('username') && $request->has('phonel')) {
    		$data = $request->only('userid','username','phonel');
    		$m = DB::table('cloud')->insertGetId($data);
	    	if ($m>0) {
	    		return redirect('home/addre');
	    	}
    	}else{
    		return back()->with('msg','添加失败!!!');
    	}
    }
    public function edit($id)
    {
    	$list = DB::table('cloud')->where('cloudid',$id)->get();
    	// dd($list);
    	return view('home.cloud.edit',['list'=>$list]);
    }
    public function update($id,Request $request)
    {
    	$data = $request->only('username','phonel');
    	DB::table('cloud')->where('cloudid',$id)->update($data);
    	return redirect('home/addre');
    }
}
